home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2006 October / wn148cd2.iso / Windows / Travailler / QuickZip / quickzip_460013.exe / {app} / Scripts / Sequence.akp < prev    next >
Text File  |  2003-05-27  |  4KB  |  140 lines

  1. const ExtractPath = 'C:\Temp\';
  2.       ArchivePath = '';
  3.       Seqformat = 'File %d';
  4.       SubDir = False;
  5.       
  6. var epath, apath, seqfmt : string;
  7.     aForm : TForm;
  8.     Button1,ExitButton,Button3,ConfirmButton : TButton;
  9.     Edit1,Edit2,Edit3 : TEdit;
  10.     Label1,Label2,Label3,Label4,Label5,Label6, Label7 : TLabel;
  11.  
  12. procedure Continueclick(sender: TObject);
  13. begin
  14.    aForm.modalResult := mrOK;
  15.    aForm.Close;
  16. end;
  17.  
  18. procedure ExitButtonClick(Sender : TObject);
  19. begin
  20.    aForm.modalResult := mrCancel;
  21.    aForm.Close;
  22. end;
  23.  
  24. function replace(source : string; fromm, too : string) : string;
  25. var i : integer;
  26. begin
  27.         i := pos(fromm,'^' + source);
  28.         if i <> 0 then
  29.         begin
  30.         i := i -1;
  31.         if i = 0 then
  32.         result := too + copy(source,length(fromm),length(source)-length(fromm)+1);
  33.         writeln(result);
  34.         result := copy(source,0,i-1) + too + copy(source,i + length(fromm),length(source)-i-length(fromm)+1);
  35.         end else
  36.         result := source;
  37. end;
  38.  
  39. function removefileext(input : string) : string;
  40. var
  41.   I: Integer;
  42. begin
  43.   I := LastDelimiter('.\:', input);
  44.   if (I > 0) and (input[I] = '.') then
  45.     Result := Copy(input, 0, i-1) else
  46.     Result := input;
  47. end;
  48.  
  49.  
  50. procedure Button1Click(sender: TObject);
  51. var k : string;
  52. begin
  53.    k := AskFilenameDialog(Edit1.text,'Zip Archive|*.zip|All Other Supported Archives|*.*');
  54.    if k <> '' then
  55.      Edit1.text := k;
  56.      
  57.    if fileexists(k) then
  58.    Edit2.text := Removefileext(Extractfilename(k)) + '-%2d';
  59. end;
  60.  
  61.  
  62. procedure Button3Click(sender: TObject);
  63. var k : string;
  64. begin
  65.    k := AskDirDialog(Edit3.text);
  66.    if k <> '' then
  67.      Edit3.text := k;
  68. end;
  69.  
  70. procedure Process;
  71. var i : integer;
  72.     newname : string;
  73. begin
  74.    Open(apath);
  75.    Sort(0,True);
  76.    UseExtrPath(SubDir);
  77.    UseExtrOverwrite(True);
  78.    Writeln('Working Archive - ' + apath);
  79.    for i := 0 to Total_Contents - 1 do
  80.      begin
  81.         Extract(Contents_Filedefpath(i) + Contents_Filename(i),epath);
  82.         newname := Replace(Format(seqfmt,[i+1]),' ','0');
  83.         Writeln(epath+Contents_Filename(i)+'-->'+epath+newname+extractfileext(Contents_Filename(i)));
  84.         RenFile(epath+Contents_Filename(i),epath+newname+extractfileext(Contents_Filename(i)));
  85.      end;
  86. end;
  87.  
  88.  
  89. function ReqInput : boolean;
  90. begin
  91.     Result := False;
  92.  
  93.     aForm := New_Form(100,100,500,240,'Sequence Rename 0.1');
  94.     Label6 := New_Label(aForm,10,10,'Please select archive file and pick destination');
  95.     Label6 := New_Label(aForm,10,30,'File in archive will be extracted and rename in sequence');
  96.     Label1 := new_Label(aForm,10,50,'Archive to Extract : ');
  97.     Edit1 := new_Edit(aForm,120,50,200,20,apath);
  98.     Button1 := New_Button(aForm, 350, 50, 100, 20, 'Browse');
  99.     Button1.OnClick := @Button1Click;
  100.     Label2 := new_Label(aForm,10,80,'Sequence format : ');
  101.     Edit2 := new_Edit(aForm,120,80,200,20,Seqfmt);
  102.     Label3 := new_Label(aForm,10,110,'Extract files to : ');
  103.     Edit3 := new_Edit(aForm,120,110,200,20,epath);
  104.     Button3 := New_Button(aForm, 350, 110, 100, 20, 'Browse');
  105.     Button3.OnClick := @Button3Click;
  106.     Label4 := new_Label(aForm,10,140,'*If SeqFormat is "File %2d", then file will be renamed to File 01, File 02, File 03 ...');
  107.     Label5 := new_Label(aForm,10,160,'%d = number');
  108.     ConfirmButton := New_Button(aForm, 350, 170, 100, 30, 'Continue');
  109.     ConfirmButton.Default := True;
  110.     ConfirmButton.ModalResult := mrOK;
  111.     ConfirmButton.OnClick := @Continueclick;
  112.     
  113.     ExitButton := New_Button(aForm, 240, 170, 100, 30, 'Quit!');
  114.     ExitButton.OnClick := @ExitButtonClick;
  115.     
  116.     show_Form(aForm);
  117.     if aForm.modalResult = Mrok then
  118.     begin
  119.     epath := Appendslash(Edit3.text);
  120.     apath := Edit1.text;
  121.     seqfmt := Edit2.text;
  122.     Result := true;
  123.     end;
  124. end;
  125.  
  126. begin
  127.    epath := Extractpath;
  128.    apath := Archivepath;
  129.    seqfmt := seqformat;
  130.    ReqInput;
  131.    if aform.modalResult = mrOK then
  132.      process;
  133.    while (aform.modalResult = mrOK) do
  134.    begin
  135.      ReqInput;
  136.      if aform.modalResult = mrOK then
  137.      process;
  138.    end;
  139. end.
  140.